<?php

namespace app\api\controller\applets;

use app\common\controller\Api;
use EasyWeChat\Factory;
use fast\Random;
use think\App;
use think\Db;
use think\facade\Validate;
use think\facade\Config;
use app\common\library\Ems;
use app\common\library\Sms;
use think\Request;

/**
 * 会员接口.
 */
class User extends Api
{
    protected $noNeedLogin = ['wechatLogin'];
    protected $noNeedRight = '*';

    protected $model;
    /**
     * 构造方法
     * @access public
     * @param Request $request Request 对象
     */
    public function __construct(Request $request = null)
    {
        parent::__construct(App::getInstance());
        $this->model = new \app\api\model\User();
    }


    public function _initialize()
    {
        parent::_initialize();
        if (!Config::get('fastadmin.usercenter')) {
            $this->error(__('User center already closed'));
        }
    }


    /**
     *  微信或支付宝小程序登录
     */
    public function wechatLogin(){
        $requestData = $this->request->post();
        $data  = $this->model->wechatLogin($requestData);
        $this->getReturnData($data);
    }


    /**
     * 优惠券弹窗.
     */
    public function couponCheck()
    {
        $requestData = $this->request->post();
        $user = $this->auth->getUserinfo();
        $data  = $this->model->couponCheck($requestData, $user);
        $this->getReturnData($data);
    }

    /**
     * 优惠券领取.
     */
    public function couponReceive()
    {
        $requestData = $this->request->post();
        $user = $this->auth->getUserinfo();
        $data  = $this->model->couponReceive($requestData, $user);
        $this->getReturnData($data);
    }

    /**
     * 我的首页.
     */
    public function mine()
    {
        $requestData = $this->request->post();
        $user = $this->auth->getUserinfo();
        $data  = $this->model->mine($requestData, $user);
        $this->getReturnData($data);
    }

    /**
     * 实名认证.
     */
    public function certified()
    {
        $requestData = $this->request->post();
        $user = $this->auth->getUserinfo();
        $data  = $this->model->certified($requestData, $user);
        $this->getReturnData($data);
    }

    /**
     * 我的资料.
     */
    public function information()
    {
        $requestData = $this->request->post();
        $user = $this->auth->getUserinfo();
        $data  = $this->model->information($requestData, $user);
        $this->getReturnData($data);
    }

    /**
     * 驾驶人列表.
     */
    public function driverList()
    {
        $requestData = $this->request->post();
        $user = $this->auth->getUserinfo();
        $data  = $this->model->driverList($requestData, $user);
        $this->getReturnData($data);
    }

    /**
     * 驾驶人新增或编辑
     */
    public function driverEdit()
    {
        $requestData = $this->request->post();
        $user = $this->auth->getUserinfo();
        $data  = $this->model->driverEdit($requestData, $user);
        $this->getReturnData($data);
    }

    /**
     * 驾驶人删除
     */
    public function driverDelete()
    {
        $requestData = $this->request->post();
        $user = $this->auth->getUserinfo();
        $data  = $this->model->driverDelete($requestData, $user);
        $this->getReturnData($data);
    }

    /**
     * 地址列表.
     */
    public function addressList()
    {
        $requestData = $this->request->post();
        $user = $this->auth->getUserinfo();
        $data  = $this->model->addressList($requestData, $user);
        $this->getReturnData($data);
    }

    /**
     * 地址新增.
     */
    public function addressAdd()
    {
        $requestData = $this->request->post();
        $user = $this->auth->getUserinfo();
        $data  = $this->model->addressAdd($requestData, $user);
        $this->getReturnData($data);
    }

    /**
     * 地址编辑.
     */
    public function addressEdit()
    {
        $requestData = $this->request->post();
        $user = $this->auth->getUserinfo();
        $data  = $this->model->addressEdit($requestData, $user);
        $this->getReturnData($data);
    }

    /**
     * 地址删除.
     */
    public function addressDelete()
    {
        $requestData = $this->request->post();
        $user = $this->auth->getUserinfo();
        $data  = $this->model->addressDelete($requestData, $user);
        $this->getReturnData($data);
    }

    /**
     * 申请加盟.
     */
    public function apply()
    {
        $requestData = $this->request->post();
        $user = $this->auth->getUserinfo();
        $data  = $this->model->apply($requestData, $user);
        $this->getReturnData($data);
    }

    /**
     * 邀请有礼.
     */
    public function invitation()
    {
        $requestData = $this->request->post();
        $user = $this->auth->getUserinfo();
        $data  = $this->model->invitation($requestData, $user);
        $this->getReturnData($data);
    }

    /**
     * 提现明细.
     */
    public function cashList()
    {
        $requestData = $this->request->post();
        $user = $this->auth->getUserinfo();
        $data  = $this->model->cashList($requestData, $user);
        $this->getReturnData($data);
    }

    /**
     * 提现.
     */
    public function cash()
    {
        $requestData = $this->request->post();
        $user = $this->auth->getUserinfo();
        $data  = $this->model->cash($requestData, $user);
        $this->getReturnData($data);
    }

    /**
     * 用户优惠券.
     */
    public function couponList()
    {
        $requestData = $this->request->post();
        $user = $this->auth->getUserinfo();
        $data  = $this->model->couponList($requestData, $user);
        $this->getReturnData($data);
    }

    /**
     * 注销登录.
     */
    public function logout()
    {
        $this->auth->logout();
        $data = ['status' => 1, 'message' => '操作成功', 'result' => ''];
        $this->getReturnData($data);
    }

}
